/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: VP Development
 * License Type: Purchased
 */
using System;
using Orm;
using System.Collections;
using NHibernate;

namespace petshop {
	/// <summary>
	/// ORM-Persistable Class
	/// </summary>
	public class Customer {
		public Customer() {
		}
		
		public bool Save() {
			try {
				global::petshop.PetShopPersistentManager.Instance().SaveObject(this);
				return true;
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		public bool Delete() {
			try {
				global::petshop.PetShopPersistentManager.Instance().DeleteObject(this);
				return true;
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		public bool Refresh() {
			try {
				global::petshop.PetShopPersistentManager.Instance().GetSession().Refresh(this);
				return true;
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		public bool DeleteAndDissociate() {
			try {
				if(Transaction != null) {
					Transaction.Customer = null;
				}
				return Delete();
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		public bool DeleteAndDissociate(global::Orm.PersistentSession session) {
			try {
				if(Transaction != null) {
					Transaction.Customer = null;
				}
				try {
					session.Delete(this);
					return true;
				}
				catch (Exception) {
					return false;
				}
			}
			catch (Exception e) {
				global::System.Console.Error.WriteLine(e.Message);
				global::System.Console.Error.WriteLine(e.StackTrace);
				throw new PersistentException(e);
			}
		}
		
		private string __name;
		
		private string __telephone;
		
		private string __address;
		
		private int __ID;
		
		private global::petshop.Transaction __transaction;
		
		public string Name {
			set {
				this.__name = value;				
			}
			get {
				return __name;				
			}
		}
		
		public string Telephone {
			set {
				this.__telephone = value;				
			}
			get {
				return __telephone;				
			}
		}
		
		public string Address {
			set {
				this.__address = value;				
			}
			get {
				return __address;				
			}
		}
		
		private int ID {
			set {
				this.__ID = value;				
			}
			get {
				return __ID;				
			}
		}
		
		public int ORMID {
			get {
				return ID;				
			}
		}
		
		public global::petshop.Transaction Transaction {
			set {
				if (__transaction != value) {
					if (this.__transaction != null) {
						this.__transaction.Customer = null;
					}
					this.__transaction = value;
					if (__transaction != null) {
						__transaction.Customer = this;
					}
				}
			}
			get {
				return __transaction;				
			}
		}
		
		public override string ToString() {
			return Convert.ToString(ID);
		}
		
	}
}
